package com.cloudcross.ssp.web.main;

import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.MapBuilder;
import com.cloudcross.ssp.common.utils.String2MapUtils;
import com.cloudcross.ssp.model.*;
import com.cloudcross.ssp.web.widget.SelectorController.ISelector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 创建人：wuqiang.du
 * 创建时间：2016.05.23 14:45
 * 下拉框类
 * 修改人：wuqiang.du
 * 修改时间：2015-05-25 10.17
 * 修改内容：下拉框改成面包屑
 */
@Controller
@RequestMapping("/main/commoncombobox")
public class CommonComboboxController {

    @Autowired
    private GenericIBatisDao myBatisDao;

    //广告主
    @RequestMapping("/advertiserCombobox")
    @ResponseBody
    public Map<String, List<? extends ISelector>> advertiserCombobox(String id) {
        List<Advertiser> advertiserList = new ArrayList<Advertiser>();
        Map<String, Object> condition = new HashMap<String, Object>();
        if (null != id && !"".equals(id) && !"0".equals(id)) {
            condition = String2MapUtils.modifyString2Map(id, "agentIdSet");
        }
        advertiserList = myBatisDao.getList("advertiserSqlMapper.queryAdvertiserCombobox", condition);
        return MapBuilder.create(HashMap.class).add("advertiserList", advertiserList).map();
    }

    //根据advertiserID来查询广告主信息
    @RequestMapping("/advertiserIdCombobox")
    @ResponseBody
    public Map<String, List<? extends ISelector>> advertiserIdCombobox(String id) {
        List<Advertiser> advertiserList = new ArrayList<Advertiser>();
        Map<String, Object> condition = new HashMap<String, Object>();
        if (null != id && !"".equals(id) && !"0".equals(id)) {
            condition = String2MapUtils.modifyString2Map(id, "advertiserIdSet");
        }
        advertiserList = myBatisDao.getList("advertiserSqlMapper.queryAdvertiserIdCombobox", condition);
        return MapBuilder.create(HashMap.class).add("advertiserList", advertiserList).map();
    }

    //订单
    @RequestMapping("/orderCombobox")
    @ResponseBody
    public Map<String, List<? extends ISelector>> orderCombobox(String id) {
        List<Order> orderList = new ArrayList<Order>();
        if (null != id && !"".equals(id) && !"0".equals(id)) {
            Map<String, Object> condition = String2MapUtils.modifyString2Map(id, "advertiserIdSet");
            orderList = myBatisDao.getList("orderSqlMapper.queryOrderCombobox", condition);
        }
        return MapBuilder.create(HashMap.class).add("orderList", orderList).map();
    }

    //投放
    @RequestMapping("/adgroupCombobox")
    @ResponseBody
    public Map<String, List<? extends ISelector>> adgroupCombobox(String id) {
        List<AdGroup> adgroupList = new ArrayList<AdGroup>();
        if (null != id && !"".equals(id) && !"0".equals(id)) {
            Map<String, Object> condition = String2MapUtils.modifyString2Map(id, "orderIdSet");
            adgroupList = myBatisDao.getList("adGroupSqlMapper.queryAdGroupCombobox", condition);
        }
        return MapBuilder.create(HashMap.class).add("adgroupList", adgroupList).map();
    }

    //媒体
    @RequestMapping("/operatorCombobox")
    @ResponseBody
    public Map<String, List<? extends ISelector>> operatorCombobox(String id) {
        List<Operator> operatorList = new ArrayList<Operator>();
        Map<String, Object> condition = new HashMap<String, Object>();
        if (null != id && !"".equals(id) && !"0".equals(id)) {
            condition = String2MapUtils.modifyString2Map(id, "operatorIdSet");
        }
        operatorList = myBatisDao.getList("operatorSqlMapper.queryOperatorCombobox", condition);
        return MapBuilder.create(HashMap.class).add("operatorList", operatorList).map();
    }
}
